var express = require('express');
var router = express.Router();
const model  = require('../db/models')

var redis = require("redis")
 /* GET home page. */
router.get('/' , async function(req, res, next)  {



  res.render('index', { title: 'Express' });
});

router.get("/add/:name",async function(req,res,next){
  let {name} =req.params;
  let test   = await  model.Test.create({name});
  res.send(test);
});

router.get("/delete/:id", async function(req,res,next){
  let {id} = req.params;
  let mo = await model.Test.destroy({where:{id}})
  res.json(mo);
});


router.get("/update/:name/:id",async (req,res,next)=>{
  let {id} =req.params;
  let {name}=req.params;
  const tmodel = await model.Test.update({ name }, {
      where: {
          id
      }}
  )
  res.json(tmodel)
});

router.get("/list", async (req,res,next)=>{
  let list  = await model.Test.findAll();
  console.log("请求成功："+Date.now().toString());
  res.json(list)
 
})
 
router.get("/r", async (req,res,next)=>{

  var client = redis.createClient(6379,'127.0.0.1');
  var result  =  await client.set("redisName1","redisValue");
   
  
  res.json(result); 
});
module.exports = router;
